package com.songshuai.webapi.baseapi.service.impl;

import com.songshuai.webapi.baseapi.dao.YixueBaseSchoolMapper;
import com.songshuai.webapi.baseapi.dto.response.SchoolResDto;
import com.songshuai.webapi.baseapi.model.YixueBaseSchool;
import com.songshuai.webapi.baseapi.service.SchoolService;
import com.songshuai.webapi.baseapi.utils.PropertiesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private YixueBaseSchoolMapper schoolMapper;

    @Override
    public List<SchoolResDto> getByName(String name,Integer limitNum) {
        List<SchoolResDto> resDtoList = new ArrayList<>();
        List<YixueBaseSchool> schoolList = schoolMapper.getByName(name,limitNum);
        for (YixueBaseSchool school: schoolList) {
            SchoolResDto resDto = new SchoolResDto();
            PropertiesUtil.copyProperties(school,resDto);
            resDtoList.add(resDto);
        }
        return resDtoList;
    }


    @Override
    public List<SchoolResDto> getByCampusId(Integer campusId) {
        List<SchoolResDto> resDtoList = new ArrayList<>();
        List<YixueBaseSchool> schoolList = schoolMapper.selectSchoolByCampus(campusId);
        for (YixueBaseSchool school: schoolList) {
            SchoolResDto resDto = new SchoolResDto();
            PropertiesUtil.copyProperties(school,resDto);
            resDtoList.add(resDto);
        }
        return resDtoList;
    }



}
